package com.neuedu.his.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.his.po.Constantitem;
import com.neuedu.his.service.ConstantitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/constantitem")
public class ConstantItemController {

    @Autowired
    ConstantitemService service;

    @RequestMapping("/list")
    public List<Constantitem> list(){

        return  service.list();
    }

    @RequestMapping("/saveconstant")
    public boolean saveconstant(@RequestBody Constantitem constantitem){
        boolean success = service.saveOrUpdate(constantitem);
        return success;
    }

    @RequestMapping("/add")
    public boolean add(@RequestBody Constantitem item){
        return service.save(item);
    }

    @RequestMapping("/getByitemId/{id}")
    public Constantitem getById(@PathVariable  Long id){
        Constantitem constantitem  = service.getById(id);
        return constantitem;
    }

    @RequestMapping("/deleteByitemId/{id}")
    public boolean deleteById(@PathVariable String id){
        boolean success = service.removeById(id);
        return success;
    }


    @RequestMapping("/getbytypeid")
    public List<Constantitem> getbytypeid(@RequestBody Map<String,String> id){
        LambdaQueryWrapper<Constantitem> queryWrapper = new LambdaQueryWrapper<>();
        System.out.println(id.get("id"));
        queryWrapper.eq(Constantitem::getConstanttypeid,Integer.parseInt(id.get("id")));
        return service.list(queryWrapper);
    }

    @RequestMapping("/getbytypeid2")
    public List<Constantitem> getbytypeid2(@RequestParam Integer id){
        System.out.println("getbytypeid2   id="+id);
        QueryWrapper<Constantitem> qw = new QueryWrapper<>();
        qw.eq("constanttypeid",id);
        return service.list(qw);
    }


}
